<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');

$shopList = Shop::GetAllShops();
//$serviceList = Service::GetAll();
//print_r($_POST['service_id']);
$device = null;
if( $_GET['id'] != null ){
	$device = Devices::GetById( abs( intval( $_GET['id'] ) ) );
	$serviceList = Service::GetAllByShopId($device['shop_id']);
}


if ( $_POST ) {
	if( $oauthMap[43] == null){
		exit;
	}
	$device = array();
	$device['device_name'] = $_POST['device_name'];
	$device['device_count'] = $_POST['device_count'];
	//$device['service_duration'] = $_POST['service_duration'];
	$device['shop_id'] = $_POST['shop_id'];
	
	$shop_id = $_POST['shop_id'];
	if( $_POST['device_id'] < 1 ){
		Logs::setLog("==============----------------service||=create");
		$deviceId = Devices::Create($device);
	}else{
		$device['id'] = $_POST['device_id'];
		Devices::Update($device);
	}
	
	
	redirect( WEB_ROOT . "/service/deviceManage.php?shop_id=$shop_id" );
}



include template('/service/device_edit');
